//
//  ApiBusiness.m
//  KangarooDoctor
//
//  Created by 廖罡 on 2024/1/12.
//

#import "ApiBusiness.h"
#import "DataModel.h"

@implementation ApiBusiness

/*
 return
 "userName": "15367956065",
 "code": null、
 */
+(void)requestSmsByPhone:(NSString*)phone
          callback:(ApiCallback)callback
{
    
  NSString *path = [NSString stringWithFormat:@"/auth/code/%@", phone];
    
   [[Api shared] getAtPath:path param:nil callback:callback];
}


/*
    获取手机的验证码
 */
+(void)verifyPhone:(NSString*)phone
           smsCode:(NSString*)smsCode
          callback:(ApiCallback)callback
{
    NSDictionary *param = @{
        @"userName": phone,
        @"code": smsCode,
    };
    
    [[Api shared] postAtPath:@"/auth/login/code" param:param callback:^(id  _Nonnull result, NSString * _Nonnull err) {
        if (err) {
            NSLog(@"fail: %@", err);
            callback(nil, err);
        }else{
            NSLog(@"ok, %@", result);
            
            NSDictionary *dict = result;
            
            GDVerifyPhoneRoot *root = [[GDVerifyPhoneRoot alloc] initWithDictionary:dict];
            
            callback(root, nil);
        }
    }];
}



+(void)getUserDetail:(NSString*)phone
          callback:(ApiCallback)callback
{
}



+(void)test
{
    NSString *phone = @"15367956065";
    
    [self verifyPhone:phone smsCode:@"643603" callback:^(id  _Nonnull result, NSString * _Nonnull err) {
        if (err) {
            NSLog(@"fail: %@", err);
        }else{
            NSLog(@"ok, %@", result);
        }
    }];
}
@end
